package SiderMain;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JPanel;

public class SiderPanel extends JPanel implements MouseListener, MouseMotionListener{
	
	public boolean running = true;
	
	private long lastTime;
	private long thisTime;
	private long deltaTime;
	private int skippedFrames;
	public int frameRate = 25;
	
	private int colorInt = 0;
	private int mousePosX = 0;
	private int mousePosY = 0;
	private boolean ascending = true;
	
	public SiderPanel() {
		lastTime = System.nanoTime();
	}

	public void run(int skippedFrms) {
		skippedFrames = skippedFrms;
		
		if(ascending){
			colorInt = (colorInt + 1 + skippedFrames);
			if(colorInt >= 255) {
				colorInt = 255;
				ascending = false;
			}
		}else{
			colorInt = (colorInt - 1 - skippedFrames);
			if(colorInt <= 0) {
				colorInt = 0;
				ascending = true;
			}
		}
		
		setBackground(new Color(colorInt, colorInt, colorInt));		
		
		
		
		thisTime = System.nanoTime();
		deltaTime = (Math.abs(thisTime-lastTime)/1000000);
		skippedFrames = (int)(deltaTime/(1000/frameRate));
		lastTime = thisTime;
		try {
			Thread.sleep((1000/frameRate)-(deltaTime%(1000/frameRate)));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		if(running){
			run(skippedFrames);
		}
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
}
